package com.commerce.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.commerce.dao.UserDao;
import com.commerce.enums.ErrorCode;
import com.commerce.exception.ResultException;
import com.commerce.pojo.po.User;
import com.commerce.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserviceImpl extends ServiceImpl<UserDao, User> implements UserService{
    @Autowired
    private UserDao userDao;

    @Override
    public User login(User user) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
        lqw.eq(User::getPhone,user.getPhone());
            User loginUser = userDao.selectOne(lqw);
            if (!loginUser.getPassword().equals(user.getPassword())){
            throw new ResultException(ErrorCode.LOGIN_FAILURE);
        }
            return loginUser;
    }
}
